package cn.ht.bootdemo.designmode.facAndmethod.service.impl;

import cn.ht.bootdemo.common.enums.ServiceEnum;
import cn.ht.bootdemo.designmode.facAndmethod.factory.UserServiceStrategyFactory;
import cn.ht.bootdemo.designmode.facAndmethod.service.UserPayService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * @author ht
 * @Description: 普通VIP打9折，消费满100打8折 的策略。
 * @date 2020-5-11
 */
@Service
public class VipPayServiceImpl implements UserPayService, InitializingBean {

    @Override
    public BigDecimal quote(BigDecimal bigDecimal) {
        if (bigDecimal.compareTo(new BigDecimal("10")) > 1){
            return new BigDecimal("8");
        }
        myShow();
        return new BigDecimal("9");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        UserServiceStrategyFactory.register(ServiceEnum.VIP_USER.getValue(),this);
    }

    public void myShow(){
        System.out.println("myShow method invoke----->");
    }
}
